import { defineStore } from "pinia"

export const useUserStore = defineStore('userStore', {
  state: () => ({
    name: 'Admin',
    age: 25,
    email: 'admin@example.com',
    token: '******************************************************'
  }),
  getters: {
    getName(state) {
      return state.name
    },
    getAge(state) {
      return state.age
    },
    getEmail(state) {
      return state.email
    }
  },
  actions: {
    setName(name: string) {
      this.name = name
    },
    setAge(age: number) {
      this.age = age
    },
    setEmail(email: string) {
      this.email = email
    }
  },
  persist: {
    // 开启持久化
    enabled: true,
    // 选择持久化方式以及持久化路径
    strategies: [
      {
        storage: localStorage,
        // key: 'user',
        paths: ['token']
      }
    ]
  }
})